import * as vscode from 'vscode';
import {dedent} from "../../../utils";

// documentation中使用了代码块，代码块中写的事makedown格式，首行不能为空
let framesItems = [
    {
        "label": "Frames_Create",
        "insertText": dedent`
        local ext = {
            count = \${1:10},
            speed = \${2:100},
            loop  =  \${3:1},
            finishhide = \${4:1}
        }
        local frames = GUI:Frames_Create(\${5:wnd}, \${6:"Frames_1"}, \${7:200}, \${8:200}, \${9:"res/public/word_fubentg_"}, \${10:".png"}, \${11:1}, \${12:10}, ext)
        `,
        "documentation": dedent`# 创建序列帧动画
        ## Frames_Create(parent, ID, x, y, prefix, suffix, beginframe, finishframe, ext)

        | 参数        | 必选 | 类型   | 注释                                                         |
        | :---------- | :--- | :----- | :----------------------------------------------------------- |
        | parent      | 是   | obj    | 父节点对象                                                   |
        | ID          | 是   | string | 唯一ID                                                       |
        | x           | 是   | int    | 位置 横坐标                                                  |
        | y           | 是   | int    | 位置 纵坐标                                                  |
        | prefix      | 是   | string | 前缀                                                         |
        | suffix      | 是   | string | 后缀                                                         |
        | beginframe  | 否   | int    | 起始帧, 默认1                                                |
        | finishframe | 否   | int    | 结束帧                                                       |
        | ext         | 否   | table  | 附加参数, {speed = 播放速度(毫秒), count = 图片数量, loop = 播放次数(-1: 循环), finishhide = 播放结束是否隐藏(1: 隐藏)} |

        - 示例代码
        \`\`\`
        local ext = {
            count = 10,
            speed = 100,
            loop  =  1,
            finishhide = 1
        }
        local frames = GUI:Frames_Create(wnd, "Frames_1", 200, 200, "res/public/word_fubentg_", ".png", 1, 10, ext)
        \`\`\`
        `
    }
]


export function getCompletionItems(): vscode.CompletionItem[] {


    const completionItems: vscode.CompletionItem[] = [];
    framesItems.forEach((item: any) => {
        completionItems.push(createFunctionCompletionItem(item.label, item.insertText, item.documentation));
    });
    return completionItems;
}

function createFunctionCompletionItem(label: string, insertText: string, documentation?: string): vscode.CompletionItem {
    const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Function);
    item.insertText = new vscode.SnippetString(insertText);
    if (documentation) {
        item.documentation = new vscode.MarkdownString(documentation);
    }
    return item;
}
